FROM nvcr.io/nvidia/l4t-jetpack:r35.4.1

WORKDIR /home
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
    sed -i 's|http://ports.ubuntu.com/ubuntu-ports/|https://repo.huaweicloud.com/ubuntu-ports/|g' /etc/apt/sources.list && \
    sed -i 's|http://archive.ubuntu.com/ubuntu|https://repo.huaweicloud.com/ubuntu-ports|g' /etc/apt/sources.list && \
    sed -i 's|http://security.ubuntu.com/ubuntu/|https://repo.huaweicloud.com/ubuntu-ports/|g' /etc/apt/sources.list && \
    apt update -y && \
    apt install -y libeigen3-dev libopenni2-dev lsb-release curl  && \
    # install pcl tool
    apt install pcl-tool -y && \
    # clean apt install cache
    apt clean && rm -rf /var/lib/apt/lists/*
# Install ROS1 Noetic
RUN sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list' && \
    curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - && \
    apt update -y && \
    apt install ros-noetic-desktop-full -y && \
    echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc && \
    /bin/bash -c "source ~/.bashrc && \
    apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential && \
    apt install ros-noetic-desktop-full -y && \
    apt clean && rm -rf /var/lib/apt/lists/* "
# compile ORBSLAM2_with_pointcloud_map
RUN apt install git python3-pip -y && \
    git config --global http.proxy socks5://127.0.0.1:7897 && \
    git config --global https.proxy socks5://127.0.0.1:7897 && \
    #--------------------------------------------------
    # Install Pangolin
    cd /home && \
    git clone https://gitee.com/boboji11/pangolin-v0.5-modified.git && \
    apt install libglew-dev cmake libboost-dev libboost-thread-dev libboost-filesystem-dev -y && \
    chmod +x pangolin-v0.5-modified/build.sh && \
    cd pangolin-v0.5-modified && \
    ./build.sh && \
    #--------------------------------------------------
    # install opencv 3.4.5
    cd /home && \
    #curl -x socks5://127.0.0.1:7897 -L -o opencv-3.4.5.zip https://github.com/opencv/opencv/archive/3.4.5.zip && \
    #unzip opencv-3.4.5.zip && \
    git clone https://gitee.com/boboji11/opencv3.4.5-modified.git && \
    cd opencv-3.4.5 && \
    chmod +x build.sh && \
    ./build.sh && \
    echo "/usr/local/opencv3.4.5/lib" >> /etc/ld.so.conf.d/opencv.conf && \
    ldconfig && \
    echo "export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/opencv3.4.5/lib/pkgconfig" >> ~/.bashrc && \
    echo "export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/opencv3.4.5/lib" >> ~/.bashrc && \
    .  ~/.bashrc && \
    apt install mlocate -y && \
    updatedb && \
    #--------------------------------------------------
    # Install ORBSLAM2_with_pointcloud_map 
    # deprecated note:
    #git clone https://github.com/raulmur/ORB_SLAM2.git && \
    #git clone https://github.com/gaoxiang12/ORBSLAM2_with_pointcloud_map.git  && \
    #mkdir -p ORBSLAM2_with_pointcloud_map/ORB_SLAM2_modified/Vocabulary/ && \
    #tar -xvf ORB_SLAM2/Vocabulary/ORBvoc.txt.tar.gz -C ORBSLAM2_with_pointcloud_map/ORB_SLAM2_modified/Vocabulary/ && \
    #./ORBSLAM2_with_pointcloud_map/ORB_SLAM2_modified/tools/bin_vocabulary && \
    #cd ORBSLAM2_with_pointcloud_map && \
    #unzip orbslam2_modified.zip -d uncompressed/ && \
    # end
    #--------------------------------------------------
    # Install ORBSLAM2_with_pointcloud_map 
    cd /home && \
    git clone https://gitee.com/boboji11/orb-slam2-pointcloud_map-modified.git && \
    cd orb-slam2-pointcloud_map-modified && \
    # compile g2o_with_orbslam2
    cd g2o_with_orbslam2 && chmod +x build.sh && ./build.sh \
    cd ../ORB_SLAM2_modified && chmod +x build_all.sh && ./build_all.sh \
    # download dataset for test
    cd /home && \
    curl -x socks5://127.0.0.1:7897 https://cvg.cit.tum.de/rgbd/dataset/freiburg1/rgbd_dataset_freiburg1_desk.tgz -o rgbd_dataset_freiburg1_desk.tgz && \
    tar -xvf rgbd_dataset_freiburg1_desk.tgz -C orb-slam2-pointcloud_map-modified/ORB_SLAM2_modified/dataset && \
    #--------------------------------------------------
    # orbslam2 with pointcloed ros version 
    #echo "export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/ORB_SLAM2_modified/Examples/ROS" >> ~/.bashrc && \
    #.  ~/.bashrc && \
    #updatedb && \
    #cd /home/ORBSLAM2_with_pointcloud_map && \
    #rospack profile && \
    #echo ${ROS_PACKAGE_PATH} 
    #--------------------------------------------------
    # install librealsense and librealsense-ros
    cd /home && \
    git clone -b v2.50.0 https://gitcode.com/IntelRealSense/librealsense.git && \
    cd librealsense && \
    apt update -y && \
    apt install git libssl-dev libusb-1.0-0-dev libudev-dev pkg-config libgtk-3-dev -y && \
    mkdir build && cd build  && \
    cmake .. -DBUILD_EXAMPLES=true -DCMAKE_BUILD_TYPE=release -DFORCE_RSUSB_BACKEND=false && make -j$(($(nproc)-1)) && sudo make install && \
    #--------------------------------------------------
    # 安装 realsense-ros
    cd /home && \
    mkdir -p realsense-ros_ws/src && cd realsense-ros_ws/src && \
    git clone -b 2.3.2 https://gitcode.com/IntelRealSense/realsense-ros.git && \
    git clone https://gitcode.com/pal-robotics/ddynamic_reconfigure.git && \
    catkin_init_workspace && \
    cd .. && \
    catkin_make clean && \
    catkin_make -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release && \
    catkin_make install && \
    #--------------------------------------------------
    # install pcd2pgm_package
    apt install python3-empy -y && \
    cd /home && \
    mkdir -p slam_ws/src && \
    cd slam_ws/src && \
    catkin_init_workspace && \
    git clone https://github.com/Hinson-A/pcd2pgm_package.git && \
    cd ../ && \
    catkin_make --pkg pcd2pgm
    echo "source /home/slam_ws/devel/setup.bash" >> ~/.bashrc && \
    . ~/.bashrc && \
    #--------------------------------------------------
